package com.xuxiang.cloud;

import com.xuxiang.cloud.ribbon.Configuration1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * @author xuxiang 2019/5/29 12:23
 */
@SpringBootApplication
@EnableDiscoveryClient
// 自定义路由策略
/*@ComponentScan(excludeFilters= {@ComponentScan.Filter(type= FilterType.ANNOTATION, value= ExcludeFromComponentScan.class)})
@RibbonClient(name = "spring-server-consul", configuration = Configuration1.class)*/
@RibbonClient(name = "spring-server-consul", configuration = Configuration1.class)
public class Application {

    @Autowired
    private LoadBalancerClient loadBalancerClient;

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    /*
    // 在没有@RibbonClient，全部受影响
    @Bean
    public RetryRule getRule() {
        return new RetryRule();
    }*/

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
